package com.chainshop.expenseRequest.service.impl;

import java.util.List;

import com.chainshop.common.core.domain.pojo.ExpenseRequests;
import com.chainshop.common.core.domain.pojo.StoreInfo;
import com.chainshop.common.utils.SecurityUtils;
import com.chainshop.expenditure.mapper.ExpenseRecordsMapper;
import com.chainshop.expenseRequest.mapper.ExpenseRequestsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chainshop.expenseRequest.service.IExpenseRequestsService;

/**
 * 存储支出申请的Service业务层处理
 * 
 * @author hmy
 * @date 2024-08-15
 */
@Service
public class ExpenseRequestsServiceImpl implements IExpenseRequestsService 
{
    @Autowired
    private ExpenseRequestsMapper expenseRequestsMapper;
    @Autowired
    private ExpenseRecordsMapper expenseRecordsMapper;

    /**
     * 查询存储支出申请的
     * 
     * @param id 存储支出申请的主键
     * @return 存储支出申请的
     */
    @Override
    public ExpenseRequests selectExpenseRequestsById(Long id)
    {
        return expenseRequestsMapper.selectExpenseRequestsById(id);
    }

    /**
     * 查询存储支出申请的列表
     * 
     * @param expenseRequests 存储支出申请的
     * @return 存储支出申请的
     */
    @Override
    public List<ExpenseRequests> selectExpenseRequestsList(ExpenseRequests expenseRequests)
    {
        return expenseRequestsMapper.selectExpenseRequestsList(expenseRequests);
    }

    /**
     * 新增存储支出申请的
     * 
     * @param expenseRequests 存储支出申请的
     * @return 结果
     */
    @Override
    public int insertExpenseRequests(ExpenseRequests expenseRequests)
    {
        Long userId = SecurityUtils.getUserId();
        StoreInfo storeInfo = expenseRecordsMapper.selectStroeByUserId(userId);
        expenseRequests.setStoreId(storeInfo.getId());

        return expenseRequestsMapper.insertExpenseRequests(expenseRequests);
    }

    /**
     * 修改存储支出申请的
     * 
     * @param expenseRequests 存储支出申请的
     * @return 结果
     */
    @Override
    public int updateExpenseRequests(ExpenseRequests expenseRequests)
    {
        return expenseRequestsMapper.updateExpenseRequests(expenseRequests);
    }

    /**
     * 批量删除存储支出申请的
     * 
     * @param ids 需要删除的存储支出申请的主键
     * @return 结果
     */
    @Override
    public int deleteExpenseRequestsByIds(Long[] ids)
    {
        return expenseRequestsMapper.deleteExpenseRequestsByIds(ids);
    }

    /**
     * 删除存储支出申请的信息
     * 
     * @param id 存储支出申请的主键
     * @return 结果
     */
    @Override
    public int deleteExpenseRequestsById(Long id)
    {
        return expenseRequestsMapper.deleteExpenseRequestsById(id);
    }
}
